<?php


namespace App\Repositories;


use App\Exceptions\BasicException;

class IndexNavRepository
{
    public function getIndexNavList($page, $perPage)
    {
        $indexNavList = app('model_index_nav')
            ->orderBy('id', 'desc')->paginate($perPage, ['*'], '', $page);
        if($indexNavList) return $indexNavList;
        throw new BasicException(98030);
    }

    public function upIndexNav($indexNav) {
        if ($indexNav['id']>0){
            $where[]=['id','=',$indexNav['id']];
            $newindexNav=app('model_index_nav')->where($where)->update($indexNav);
            if ($newindexNav===false) throw new BasicException(98031);
            return;
        }
        $newindexNav=app('model_index_nav')->create($indexNav);
        if (empty($newindexNav)) throw new BasicException(98031);
    }

    public function del($id)
    {
        $newindexNav=app('model_index_nav')->where("id",'=', $id)->delete();
        if (empty($newindexNav)) throw new BasicException(98031);
    }

}
